#!/usr/bin/python

import comar

class UserInfo:
    def __init__(self, uid):
        link = comar.Link()
        link.call("User.Manager.userInfo", {"uid": uid})
        data = link.read_cmd().data
        
        for x in [i.split() for i in data.split('\n')]:
            self.__dict__[x[0]] = " ".join(x[1:])

class GroupInfo:
    def __init__(self, gid):
        self.name = False
        for group in List().getGroups():
            if gid == group[0]:
                self.name = group[1]

class List:
    def __init__(self):
        self.link = comar.Link()
    
    def getUsers(self, system=False):
        self.link.call("User.Manager.userList")
        reply = self.link.read_cmd()
        output = []
        for users in reply.data.split("\n"):
            user = users.split("\t")
            uid = int(user[0])
            name = user[1]
            realname = user[2]
            
            output.append([uid,name,realname])
        
        return output
    
    def getGroups(self):
        self.link.call("User.Manager.groupList")
        reply = self.link.read_cmd()
        output = []
        for groups in reply.data.split("\n"):
            group = groups.split("\t")
            output.append([int(group[0]), group[1]])
        return output
